<template>
    <div>
        <a-table ref="table" size="middle" rowKey="id" :columns="columns"
                 :dataSource="dataSource"
                 :pagination="ipagination"
                 :loading="loading"
                 :rowSelection="isSelect?{type:'radio',onChange:onSelectChange}:null"
                 @change="handleTableChange">
            <template slot="操作" slot-scope="text,record">
                <a @click="showPhone(text,record)">预览</a>
            </template>
        </a-table>
        <preview ref="preview"></preview>
    </div>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import Preview from '@/components/xinke/preview/Preview'
  import { postAction } from '@/api/manage'

  export default {
    name: 'ContentBankListModel',
    mixins:[JeecgListMixin],
    components:{Preview},
    props:{
      isSelect:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {
        // 表头
        columns: [
          {
            title: '标题名称',
            align: 'center',
            dataIndex: 'contentTitle'
          },
          {
            title: '副标题',
            align: 'center',
            dataIndex: 'contentSubTitle'
          },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: '操作',
            width: '150px',
            scopedSlots: { customRender: '操作' }
          }
        ],
        url: {
          list: 'task/taskInfo/conContentBankList'
        }
      }
    },
    methods: {
      loadData(arg) {
        if (arg === 1) {
          this.ipagination.current = 1
        }
        const params = this.getQueryParams()
        params.state = 1
        this.loading = true
        postAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      showPhone(text, record) {
        record.richContent = record.content;
        this.$refs.preview.show(record);
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        if(selectedRows && selectedRows.length){
          const item = selectedRows[0];
          this.$emit('selectChange',item);
        }else{
          this.$emit('selectChange',{});
        }
      }
    }
  }
</script>

<style scoped>

</style>
